use my_rust_core::security::{
    auth_request_validator::UserActiveTokenManager, request_map_manager::RequestMapQuery,
};

use sea_orm::DatabaseConnection;
use std::sync::Arc;

use crate::{
    security::{
        security_request_map_query::RequestMapQueryImpl,
        user_active_token_manager::UserActiveTokenManagerImpl,
    },
    services::{
        account_group_service::{AccountGroupService, AccountGroupServiceImpl},
        account_group_user_service::AccountGroupUserServiceImpl,
        authentication_service::{AuthenticationService, AuthenticationServiceImpl},
        request_map_service::{RequestMapService, RequestMapServiceImpl},
        role_service::{RoleService, RoleServiceImpl},
        user_active_token_service::UserActiveTokenServiceImpl,
        user_role_service::UserRoleServiceImpl,
        user_service::UserServiceImpl,
    },
};

#[derive(Clone)]
pub struct AppService {
    // pub account_group_user_service: Arc<dyn AccountGroupUserService>,
    pub request_map_service: Arc<dyn RequestMapService>,
    pub role_service: Arc<dyn RoleService>,
    pub request_map_query: Arc<dyn RequestMapQuery>,
    pub user_active_token_manager: Arc<dyn UserActiveTokenManager>,
    // pub user_role_service: Arc<dyn UserRoleService>,
    pub account_group_service: Arc<dyn AccountGroupService>,
    // pub user_active_token_service: Arc<dyn UserActiveTokenService>,
    // pub user_service: Arc<dyn UserService>,
    pub authentication_service: Arc<dyn AuthenticationService>,
}

impl AppService {
    pub fn new(db: Arc<DatabaseConnection>) -> Self {
        let account_group_user_service = Arc::new(AccountGroupUserServiceImpl::new(db.clone()));
        let request_map_service = Arc::new(RequestMapServiceImpl::new(db.clone()));
        let role_service = Arc::new(RoleServiceImpl::new(db.clone()));
        let request_map_query = Arc::new(RequestMapQueryImpl::new(db.clone()));
        let user_active_token_manager = Arc::new(UserActiveTokenManagerImpl::new(db.clone()));
        let user_role_service = Arc::new(UserRoleServiceImpl::new(db.clone()));

        let account_group_service = Arc::new(AccountGroupServiceImpl::new(
            db.clone(),
            role_service.clone(),
        ));

        let user_active_token_service = Arc::new(UserActiveTokenServiceImpl::new(
            db.clone(),
            user_active_token_manager.clone(),
        ));

        let user_service = Arc::new(UserServiceImpl::new(
            db.clone(),
            account_group_user_service.clone(),
            user_role_service.clone(),
        ));

        let authentication_service = Arc::new(AuthenticationServiceImpl::new(
            user_service.clone(),
            user_active_token_service.clone(),
        ));

        AppService {
            // account_group_user_service,
            request_map_service,
            role_service,
            request_map_query,
            user_active_token_manager,
            // user_role_service,
            account_group_service,
            // user_active_token_service,
            // user_service,
            authentication_service,
        }
    }
}
